package com.wyix.service;

import com.wyix.domain.UserRepository;
import com.wyix.domian.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author wangdx
 * @since 2025/8/21
 */
@Service
public class UserService {
    @Autowired
    private UserRepository baseRepository;

    //新增
    public User save(User user) {
        return baseRepository.save(user);
    }

    //查询所有用户
    public List<User> findAll() {
        return baseRepository.findAll();
    }

    //根据ID查询用户
    public Optional<User> findById(Long id) {
        return baseRepository.findById(id);
    }

    //根据年龄查询用户
    public List<User> findByAge(Integer age) {
        return baseRepository.findByAge(age);
    }

    //更新用户
    public User update(User user) {
        return baseRepository.save(user);
    }

    //删除用户
    public void deleteById(Long id) {
        baseRepository.deleteById(id);
    }
}
